/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: network_binding.h
 *
 * Purpose: network binding  base class
 *
 * Developer:
 *   wen.gu , 2021-1-31
 *
 * TODO:
 *
 ***************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __COM_NETWORK_BINDING_H__
#define __COM_NETWORK_BINDING_H__

#include <string>
#include <functional>

#include "collie/core/types.h"
#include "collie/core/errors.h"
#include "collie/com/com_types.h"

/******************************************************************************
 **    MACROS
 ******************************************************************************/


/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/
namespace collie
{
namespace com
{
 using NetworkBindingMonitor = std::function<void(SessionId src_id, bool alive)>;
 using NetworkBindingReceiver = std::function<void(SessionId src_id, const uint8_t* data, uint32_t len)>;
/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/

class CORE_CLASS NetworkBinding
{
public:
    using CollieErrc = collie::core::CollieErrc;
public:
    NetworkBinding()       
    {
        //todo something
    }
    virtual ~NetworkBinding()
    {
        //todo something
    }

public:
    virtual CollieErrc Initialize(NetworkBindingMonitor monitor,
                                  NetworkBindingReceiver receiver,
                                  const std::string& url,
                                  bool service_or_proxy = true)
    {
        service_or_proxy_ = service_or_proxy;
        url_ = url;
        monitor_ = monitor;
        receiver = receiver;
        return CollieErrc::OK;
    }

public:
    virtual CollieErrc Start() = 0;
    virtual CollieErrc Stop() = 0;

public:
    virtual CollieErrc SendData(uint8_t* data, uint32_t len, int32_t target_id) = 0;
    
public:
    virtual const std::string& url() { return url_; }
    virtual bool service_or_proxy() { return service_or_proxy_; }

protected:
    bool service_or_proxy_ = false; /** true: as service, false: as proxy */
    std::string url_;
    NetworkBindingMonitor monitor_;
    NetworkBindingReceiver receiver_;
};

} /** namespace com */
} /** namespace collie */

#endif /** !__COM_NETWORK_BINDING_H__ */

